import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:ichinesereader/constants.dart';
import 'package:ichinesereader/controller/cache.dart';
import 'package:ichinesereader/models/book/BookIdList.dart';
import 'package:ichinesereader/models/book/BookQuizAnswerDto.dart';
import 'package:ichinesereader/models/book/BookSearchDto.dart';
import 'package:ichinesereader/utils/log.dart';
import 'package:get/get.dart';

class BookServiceProvider extends GetConnect {
  BookServiceProvider() {
    httpClient.addResponseModifier((request, response) {
      if (response.statusCode == 403) {
        Log.debug('${request.url} 403 error');
        if (!Get.isSnackbarOpen) {
          Get.snackbar(
            'Message'.tr,
            'You have been logged out due to inactivity or security reasons.'
                .tr,
            snackPosition: SnackPosition.BOTTOM,
            backgroundColor: Color(0xff23c6c8),
            colorText: Color(0xffd8ffff),
          );
        }
        if (EasyLoading.isShow) {
          EasyLoading.dismiss();
        }
        if (Get.currentRoute != '/login') {
          return Get.offAllNamed('/login');
        }
      } else if (response.statusCode == 401) {
        Log.debug('${request.url} unauthorized access');
        if (!Get.isSnackbarOpen) {
          Get.snackbar('Message'.tr, 'Unauthorized access'.tr,
              backgroundColor: Color(0xff23c6c8),
              colorText: Color(0xffd8ffff),
              snackPosition: SnackPosition.BOTTOM);
        }
        if (EasyLoading.isShow) {
          EasyLoading.dismiss();
        }
        if (Get.currentRoute != '/login') {
          return Get.offAllNamed('/login');
        }
      } else {
        Log.debug(response.request?.url.toString());
        return response;
      }
    });
    httpClient.maxAuthRetries = 2;
    httpClient.timeout = Duration(seconds: 30);
  }

/////OpenReadingBooksResult
  Future<dynamic> getOpenReadingBooks(int limit, int page) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await post(
        '${Constants.BaseAPI}superadmin/page/openreadingnew?limit=$limit&page=$page',
        jsonEncode({}),
        headers: <String, String>{
          'authtoken': _authtoken,
          'content-type': 'application/json;charset=UTF-8'
        });
    return response;
  }

/////search books with parameters
  Future<dynamic> searchOpenReadingBooks(
      int limit, int page, BookSearchDto searchDto, String? sortField) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await post(
      '${Constants.BaseAPI}superadmin/page/openreadingnew?limit=$limit&page=$page&sortField=$sortField',
      jsonEncode(searchDto),
      headers: <String, String>{
        'authtoken': _authtoken,
        'content-type': 'application/json;charset=UTF-8'
      },
      // body:
    );
    return response;
  }

  Future<dynamic> searchProgressreadingBooks(
      int limit, int page, BookSearchDto searchDto) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await post(
      '${Constants.BaseAPI}superadmin/progressreadingnew?limit=$limit&page=$page',
      jsonEncode(searchDto),
      headers: <String, String>{
        'authtoken': _authtoken,
        'content-type': 'application/json;charset=UTF-8'
      },
      // body:
    );
    return response;
  }

  Future<dynamic> searchProgressreadingBooksForChild(
      String userName, BookSearchDto searchDto) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await post(
      '${Constants.BaseAPI}superadmin/child/progressreading/$userName',
      jsonEncode(searchDto),
      headers: <String, String>{
        'authtoken': _authtoken,
        'content-type': 'application/json;charset=UTF-8'
      },
      // body:
    );
    return response;
  }

  Future<dynamic> getProgramBooklists(String programId) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await get(
      '${Constants.BaseAPI}superadmin/book/list/program/$programId',
      headers: <String, String>{
        'authtoken': _authtoken,
        'content-type': 'application/json;charset=UTF-8'
      },
    );
    return response;
  }

//////List<ProgressReadingBook>
  Future<dynamic> getProgressReadingBooks(int limit, int page) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await post(
      '${Constants.BaseAPI}superadmin/progressreadingnew?limit=$limit&page=$page',
      jsonEncode({}),
      headers: <String, String>{
        'authtoken': _authtoken,
        'content-type': 'application/json;charset=UTF-8'
      },
      //body: jsonEncode({})
    );
    return response;
  }

  Future<dynamic> getProgressReadingBooksTotalNumber(
      BookSearchDto searchDto) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await post(
      '${Constants.BaseAPI}superadmin/progressreadingcount',
      jsonEncode(searchDto),
      headers: <String, String>{
        'authtoken': _authtoken,
        'content-type': 'application/json;charset=UTF-8'
      },
      //body: jsonEncode({})
    );
    return response;
  }

////List<NewBook>
  Future<dynamic> getNewBooks() async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await get('${Constants.BaseAPI}superadmin/getNewBooks',
        headers: <String, String>{
          'authtoken': _authtoken,
        });
    return response;
  }

  Future<dynamic> getNewBooksDataForDays(int days) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await get(
        '${Constants.BaseAPI}schoolmanager/getNewBookList?days=10',
        headers: <String, String>{
          'authtoken': _authtoken,
        });
    return response;
  }

  ///MostReadBooksResult
  Future<http.Response> getMostReadBooks() async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    Uri url =
        Uri.parse('${Constants.BaseAPI}schoolmanager/getMostReadBookList');
    final response = await http.get(url,
        //'${Constants.BaseAPI}schoolmanager/getMostReadBookList',
        headers: <String, String>{
          'authtoken': _authtoken,
          'content-type': 'application/json;charset=UTF-8'
        });
    Log.debug(response.request?.url.toString());
    return response;
  }

  ///audio book list result
  Future<dynamic> getAudioBookListResult() async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await get('${Constants.BaseAPI}studentmanager/queue',
        headers: <String, String>{
          'authtoken': _authtoken,
          'content-type': 'application/json;charset=UTF-8'
        });
    return response;
  }

  ///add books to playlist
  Future<dynamic> addBooksToAudioPlaylist(List<String> bookIds) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await post('${Constants.BaseAPI}studentmanager/queue/',
        jsonEncode(BookIdList(bookId: bookIds)), headers: <String, String>{
      'authtoken': _authtoken,
      'content-type': 'application/json;charset=UTF-8'
    });
    return response;
  }

  ///delete book from playlist
  Future<dynamic> removeBooksFromAudioPlaylist(String bookId) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await delete(
        '${Constants.BaseAPI}studentmanager/queue/$bookId',
        headers: <String, String>{
          'authtoken': _authtoken,
          'content-type': 'application/json;charset=UTF-8'
        });
    return response;
  }

/////MostReadBooksResult
  Future<http.Response> getSchoolMostReadBooks() async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    Uri url =
        Uri.parse('${Constants.BaseAPI}schoolmanager/getSchoolMostReadList');
    final response = await http.get(url,
        // '${Constants.BaseAPI}schoolmanager/getSchoolMostReadList',
        headers: <String, String>{
          'authtoken': _authtoken,
          'content-type': 'application/json;charset=UTF-8'
        });
    Log.debug(response.request?.url.toString());
    return response;
  }

////List<ProgramType>
  Future<dynamic> getAllProgramTypes() async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await get(
        '${Constants.BaseAPI}superadmin/viewAllProgramType',
        headers: <String, String>{
          'authtoken': _authtoken,
          'content-type': 'application/json;charset=UTF-8'
        });
    return response;
  }

  ///BookFolders
  Future<dynamic> getBookFolders() async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    bool isSchooladmin = box.get(CacheManagerKey['nanhairole'].toString()) ==
        Constants.NanhaiRole_SchoolAdmin;
    if (!isSchooladmin) {
      //Uri url = Uri.parse('${Constants.BaseAPI}studentmanager/folderlist');
      final response = await get(
          '${Constants.BaseAPI}studentmanager/folderlist',
          headers: <String, String>{
            'authtoken': _authtoken,
            'content-type': 'application/json;charset=UTF-8'
          });
      return response;
    } else {
      return new Response(
          bodyString:
              '"{"allFolder":[{"id":"ROOTFOLDER","folderName":"Main Folder","bookCount":0}]}"',
          statusCode: 200);
    }
  }

  Future<dynamic> getBookFoldersForChild(String userName) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());

    final response = await get(
        '${Constants.BaseAPI}studentmanager/child/folderlist/$userName',
        headers: <String, String>{
          'authtoken': _authtoken,
          'content-type': 'application/json;charset=UTF-8'
        });
    return response;
  }

//////MyLibraryBooks
  Future<dynamic> getMyLibraryBooksByFoldId(String foldId, limit, page) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await get(
      '${Constants.BaseAPI}studentmanager/folder/$foldId/booknew?limit=$limit&page=$page',
      //'${Constants.BaseAPI}studentmanager/folder/$foldId/booknew',
      headers: <String, String>{
        'authtoken': _authtoken,
        'content-type': 'application/json;charset=UTF-8'
      },
      //body: jsonEncode({})
    );
    return response;
  }

  //////MyLibraryBooksparent
  Future<dynamic> getChildLibraryBooksByFoldId(
      String foldId, String userName) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await get(
      '${Constants.BaseAPI}studentmanager/child/folder/$foldId/$userName',
      //jsonEncode({}),
      headers: <String, String>{
        'authtoken': _authtoken,
        'content-type': 'application/json;charset=UTF-8'
      },
      //body: jsonEncode({})
    );
    return response;
  }

//{"status":1000,"message":"Folder is created successfully","result":{}}
  Future<dynamic> addLibraryFolder(String folderName) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await post(
      '${Constants.BaseAPI}studentmanager/folder',
      //jsonEncode("{'folderName': '$folderName'}"), // this dosn't work
      jsonEncode({'folderName': '$folderName'}),
      headers: <String, String>{
        'authtoken': _authtoken,
        'content-type': 'application/json;charset=UTF-8'
      },
      //body: jsonEncode("{'folderName': '$folderName'}"),
    );
    return response;
  }

  Future<dynamic> updateLibraryFolderName(
      String folderId, String newFolderName) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await put(
      '${Constants.BaseAPI}studentmanager/folder/$folderId',
      jsonEncode({'folderName': '$newFolderName'}),
      headers: <String, String>{
        'authtoken': _authtoken,
        'content-type': 'application/json;charset=UTF-8'
      },
      //body: jsonEncode("{'folderName': '$folderName'}"),
    );
    return response;
  }

  Future<dynamic> deleteLibraryFolder(String folderId) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    Uri url = Uri.parse('${Constants.BaseAPI}studentmanager/folder/$folderId');
    final response = await http.delete(
      url,
      //'${Constants.BaseAPI}sstudentmanager/folder/$folderId',
      headers: <String, String>{
        'authtoken': _authtoken,
        'content-type': 'application/json;charset=UTF-8'
      },
    );
    Log.debug(response.request?.url.toString());
    return response;
  }

//{"status":1000,"message":"Books are added to 春节","result":null}
  Future<dynamic> addBookItemsToLibraryFolder(
      String? foldId, List<String> bookIds) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await post(
      '${Constants.BaseAPI}studentmanager/folder/$foldId/book',
      //jsonEncode(bookIds),
      jsonEncode({'bookId': bookIds}),
      headers: <String, String>{
        'authtoken': _authtoken,
        'content-type': 'application/json;charset=UTF-8'
      },
      //body: jsonEncode(bookIds),
    );
    return response;
  }

  Future<http.Response> deleteBookItemsFromLibraryFolder(
      String? foldId, List<String> bookIds) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    Uri url =
        Uri.parse('${Constants.BaseAPI}studentmanager/folder/$foldId/book');
    final response = await http.delete(url,
        //jsonEncode({'bookId': bookIds}),
        headers: <String, String>{
          'authtoken': _authtoken,
          'content-type': 'application/json;charset=UTF-8'
        },
        body: jsonEncode({'bookId': bookIds}));
    Log.debug(response.request?.url.toString());
    return response;
  }

  Future<dynamic> getBookQuiz(String bookId) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await get(
      '${Constants.BaseAPI}superadmin/quiz/$bookId',
      headers: <String, String>{
        'authtoken': _authtoken,
        'content-type': 'application/json;charset=UTF-8'
      },
      //body: jsonEncode({}),
    );
    return response;
  }

  Future<dynamic> postBookQuizAnswer(
      String bookId, BookQuizAnswerDto dto) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await post(
      '${Constants.BaseAPI}superadmin/quiz/$bookId',
      bookQuizAnswerDtoToJson(dto),
      headers: <String, String>{
        'authtoken': _authtoken,
        'content-type': 'application/json;charset=UTF-8'
      },
    );
    return response;
  }

  Future<dynamic> getAssignmentBookQuiz(
      String bookId, String assignmentId) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await get(
      '${Constants.BaseAPI}superadmin/quiz/$assignmentId/$bookId',
      headers: <String, String>{
        'authtoken': _authtoken,
        'content-type': 'application/json;charset=UTF-8'
      },
    );
    return response;
  }

  Future<dynamic> postAssignmentBookQuizAnswer(
      String bookId, String assignmentId, BookQuizAnswerDto dto) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await post(
      '${Constants.BaseAPI}superadmin/quiz/$assignmentId/$bookId',
      bookQuizAnswerDtoToJson(dto),
      headers: <String, String>{
        'authtoken': _authtoken,
        'content-type': 'application/json;charset=UTF-8'
      },
      //body: jsonEncode({}),
    );
    return response;
  }

  Future<dynamic> getBooksDataSummary() async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await get(
      '${Constants.BaseAPI}schoolmanager/getBookSummary',
      headers: <String, String>{
        'authtoken': _authtoken,
        'content-type': 'application/json;charset=UTF-8'
      },
      //body: jsonEncode({}),
    );
    return response;
  }

  // Future<dynamic> refreshLevelPercentage() async {
  //   final box = Hive.box('appconfig');
  //   var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
  //   final response = await get(
  //     '${Constants.BaseAPI}usermanager/refreshLevelPercentage',
  //     headers: <String, String>{
  //       'authtoken': _authtoken,
  //       'content-type': 'application/json;charset=UTF-8'
  //     },
  //   );
  //   return response;
  // }

  Future<http.Response> getBooksFilters() async {
    Uri url = Uri.parse('${Constants.BaseResources}common/json/filter.json');
    final response = await http.get(
      url,
      headers: <String, String>{
        'content-type': 'application/json;charset=UTF-8'
      },
    );
    Log.debug(response.request?.url.toString());
    return response;
  }

  Future<dynamic> getBookFullHtmlText(String bookCode) async {
    var uri = Uri.parse(
        'https://resources.ichinesereader.com/books/$bookCode/content.html');
    final response = await http.get(
      uri,
      headers: <String, String>{'content-type': 'text/html;charset=UTF-8'},
    );
    return response;
  }

  Future<dynamic> getBookCategorySeries() async {
    final response = await get(
      '${Constants.BaseAPISuper}superadmin/viewAllCategoryForSeries',
      headers: <String, String>{
        'content-type': 'application/json;charset=UTF-8'
      },
    );
    return response;
  }

  Future<dynamic> getRecording(bookId, assignmentId) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    String studentName = box.get(CacheManagerKey['username']);
    String path =
        '${Constants.BaseAPI}studentmanager/recording/$studentName/$bookId';
    //Log.debug('assignmentId------${assignmentId}');
    if (assignmentId != '' && assignmentId != null) {
      path =
          '${Constants.BaseAPI}studentmanager/recording/$studentName/$bookId/$assignmentId';
    }

    final response = await get(
      path,
      headers: <String, String>{
        'authtoken': _authtoken,
        'content-type': 'application/json;charset=UTF-8',
      },
    );
    return response;
  }

  Future<dynamic> downloadFileLocationg(fileId) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await get(
      '${Constants.BaseAPI}studentmanager/location/file/$fileId',
      headers: <String, String>{
        'authtoken': _authtoken,
        'content-type': 'application/json;charset=UTF-8',
      },
    );
    return response;
  }

  Future<dynamic> readProgress(bookId, assignmentId, readProgress) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    var url = '${Constants.BaseAPI}superadmin/read/$bookId';
    if (assignmentId != '' && assignmentId != null) {
      url = '${Constants.BaseAPI}superadmin/read/$assignmentId/$bookId';
    }
    final response = await post(url, jsonEncode({'readNow': readProgress}),
        headers: <String, String>{
          'authtoken': _authtoken,
          'content-type': 'application/json;charset=UTF-8'
        });
    return response;
  }

  Future<dynamic> getWriting(bookId, assignmentId) async {
    final box = Hive.box('appconfig');
    String studentName = box.get(CacheManagerKey['username']);
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    var url = '${Constants.BaseAPI}studentmanager/writing/$studentName/$bookId';
    if (assignmentId != '' && assignmentId != null) {
      url =
          '${Constants.BaseAPI}studentmanager/writing/$studentName/$bookId/$assignmentId';
    }
    final response = await get(url, headers: <String, String>{
      'authtoken': _authtoken,
      'content-type': 'application/json;charset=UTF-8'
    });
    return response;
  }

  Future<dynamic> saveWriting(bookId, assignmentId, writing) async {
    final box = Hive.box('appconfig');
    String studentName = box.get(CacheManagerKey['username']);
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    var data;
    if (assignmentId != '' && assignmentId != null) {
      data = {
        'userId': studentName,
        'text': writing,
        'bookId': bookId,
        'assignmentId': assignmentId
      };
    } else {
      data = {'userId': studentName, 'text': writing, 'bookId': bookId};
    }
    final response = await post(
        '${Constants.BaseAPI}studentmanager/writing', jsonEncode(data),
        headers: <String, String>{
          'authtoken': _authtoken,
          'content-type': 'application/json;charset=UTF-8'
        });
    return response;
  }

  Future<dynamic> shareWriting(bookId, assignmentId, writing) async {
    final box = Hive.box('appconfig');
    String studentName = box.get(CacheManagerKey['username']);
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    var data;
    if (assignmentId != '' && assignmentId != null) {
      data = {
        'userId': studentName,
        'text': writing,
        'bookId': bookId,
        'assignmentId': assignmentId
      };
    } else {
      data = {'userId': studentName, 'text': writing, 'bookId': bookId};
    }
    final response = await post(
        '${Constants.BaseAPI}studentmanager/writing', jsonEncode(data),
        headers: <String, String>{
          'authtoken': _authtoken,
          'content-type': 'application/json;charset=UTF-8'
        });
    if (response.statusCode == 200) {
      var url =
          '${Constants.BaseAPI}studentmanager/writing/send/$studentName/$bookId';
      if (assignmentId != '' && assignmentId != null) {
        url =
            '${Constants.BaseAPI}studentmanager/writing/send/$studentName/$bookId/$assignmentId';
        final response = await put(
            url,
            jsonEncode({
              'userId': studentName,
              'text': writing,
              'bookId': bookId,
              'assignmentId': assignmentId
            }),
            headers: <String, String>{
              'authtoken': _authtoken,
              'content-type': 'application/json;charset=UTF-8'
            });
        Log.debug('inside teacher writing response ${response.statusCode}');
        return response;
      } else {
        final response = await put(
            url,
            jsonEncode(
                {'userId': studentName, 'text': writing, 'bookId': bookId}),
            headers: <String, String>{
              'authtoken': _authtoken,
              'content-type': 'application/json;charset=UTF-8'
            });
        return response;
      }
    }
  }

  Future<dynamic> fetchgRecommendedBookItems(String bookId) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await post(
      '${Constants.BaseAPI}superadmin/recommendreading/$bookId',
      jsonEncode({}),
      headers: <String, String>{
        'authtoken': _authtoken,
        'content-type': 'application/json;charset=UTF-8'
      },
    );
    return response;
  }

  Future<dynamic> checkIfBookAssigned(String classId, idresults) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await post(
      '${Constants.BaseAPI}schoolmanager/checkIfBooksAssigned/$classId',
      jsonEncode({'books': idresults}),
      headers: <String, String>{
        'authtoken': _authtoken,
        'content-type': 'application/json;charset=UTF-8'
      },
    );
    return response;
  }

  Future<dynamic> checkBookLightStatus(idresults) async {
    final box = Hive.box('appconfig');
    var _authtoken = box.get(CacheManagerKey['authtoken'].toString());
    final response = await get(
      '${Constants.BaseAPISuper}superadmin/examination/library/light?bookCodes=${idresults.join(",")}',
      headers: <String, String>{
        'authtoken': _authtoken,
        'content-type': 'application/json;charset=UTF-8'
      },
    );
    return response;
  }
}
